//
// Created by Jisam on 2024/6/29.
//
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x) {
    if (x < 2) return false;
    for (int j = 2; j * j <= x; j++) {
        if (x % j == 0) {
            return false;
        }
    }
    return true;
}

bool isPalindrome(int x) {
    string s = to_string(x);
    string rev_s = s;
    reverse(rev_s.begin(), rev_s.end());
    return s == rev_s;
}

vector<int> generatePalindromes(int a, int b) {
    vector<int> palindromes;

    // Generate single-digit and double-digit palindromes
    for (int i = a; i <= min(b, 99); ++i) {
        if (isPalindrome(i)) palindromes.push_back(i);
    }

    // Generate triple-digit palindromes
    for (int i = 1; i <= 9; i+=2) { // Only odd digits can be the first digit of a prime
        for (int j = 0; j <= 9; ++j) {
            int palindrome = 100 * i + 10 * j + i;
            if (palindrome >= a && palindrome <= b) palindromes.push_back(palindrome);
        }
    }

    // Generate four-digit palindromes
    for (int i = 1; i <= 9; i+=2) { // Only odd digits can be the first digit of a prime
        for (int j = 0; j <= 9; ++j) {
            int palindrome = 1000 * i + 100 * j + 10 * j + i;
            if (palindrome >= a && palindrome <= b) palindromes.push_back(palindrome);
        }
    }

    // Generate five-digit palindromes
    for (int i = 1; i <= 9; i+=2) { // Only odd digits can be the first digit of a prime
        for (int j = 0; j <= 9; ++j) {
            for (int k = 0; k <= 9; ++k) {
                int palindrome = 10000 * i + 1000 * j + 100 * k + 10 * j + i;
                if (palindrome >= a && palindrome <= b) palindromes.push_back(palindrome);
            }
        }
    }

    // Generate six-digit palindromes
    for (int i = 1; i <= 9; i+=2) { // Only odd digits can be the first digit of a prime
        for (int j = 0; j <= 9; ++j) {
            for (int k = 0; k <= 9; ++k) {
                int palindrome = 100000 * i + 10000 * j + 1000 * k + 100 * k + 10 * j + i;
                if (palindrome >= a && palindrome <= b) palindromes.push_back(palindrome);
            }
        }
    }

    // Generate seven-digit palindromes
    for (int i = 1; i <= 9; i+=2) { // Only odd digits can be the first digit of a prime
        for (int j = 0; j <= 9; ++j) {
            for (int k = 0; k <= 9; ++k) {
                for (int l = 0; l <= 9; ++l) {
                    int palindrome = 1000000 * i + 100000 * j + 10000 * k + 1000 * l + 100 * k + 10 * j + i;
                    if (palindrome >= a && palindrome <= b) palindromes.push_back(palindrome);
                }
            }
        }
    }

    // Continue generating higher-digit palindromes if needed

    return palindromes;
}

int main() {
    int a, b;
    cin >> a >> b;

    vector<int> palindromes = generatePalindromes(a, b);

    for (int num : palindromes) {
        if (isPrime(num)) {
            cout << num << endl;
        }
    }

    return 0;
}